import * as types from '../constants/ActionTypes'

const initialState = {
  isLoading: false,
}

export default function login(state = initialState, action) {
  switch (action.type) {
    case types.LOGINING:
			return {
        isLoading: true,
        uname: action.uname,
        pwd: action.pwd,
        errorMessage: 'OK',
      };
    case types.LOGINSUCCESS:
      return Object.assign({}, state, {
        isLoading: false,
        isLoginSuccess: true,
        uname: action.uname,
        merid: action.merid,
      });
    case types.LOGINFAIL:
      return Object.assign({}, state, {
        isLoading: false,
        isLoginSuccess: false,
        errorMessage: action.errorMessage,
      });
    case 'clear':
      return initialState;
    default:
      return state;   
  }
}